package com.foreknow.demo8;

import java.util.ArrayList;
import java.util.List;

public class Test1 {
    public void m1(Student[] s) {
        for(int i = 0;i<s.length;i++){
            Student ss = s[i];
            System.out.println(ss.getSname());
        }
    }

    public Student[] m2() {
        Student s1 = new Student();
        s1.setSname("fender");
        Student s2 = new Student();
        s2.setSname("gibson");
        Student[] students = new Student[2];
        students[0] = s1;
        students[1] = s2;
        return students;
    }

    public void m3(List<Student> list) {
        for (Student s:list) {
            System.out.println(s.getSname());
        }
    }

    public List<Student> m4() {
        List<Student> list = new ArrayList<>();
        Student s1 = new Student();
        s1.setSname("fender");
        Student s2 = new Student();
        s2.setSname("gibson");
        list.add(s1);
        list.add(s2);
        return list;
    }

    public static void main(String[] args) {
//        Student s1 = new Student();
//        s1.setSname("fender");
//        Student s2 = new Student();
//        s2.setSname("gibson");
//        Student[] students = new Student[2];
//        students[0] = s1;
//        students[1] = s2;
        //访问数组中的元素
//        for(int i = 0;i<students.length;i++){
//            Student s = students[i];
//            System.out.println(s.getSname());
//        }
        //调用m1方法
        Test1 test1 = new Test1();
//        test1.m1(students);
        Student[] students = test1.m2();
        for(int i = 0;i<students.length;i++){
            Student s = students[i];
            System.out.println(s.getSname());
        }



    }
}
